package com.gislife.a4.modules.business.dto.base;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * BasePageResVO
 * 基础分页出参
 *
 * @author lsw
 * @date 2020/8/27 9:36
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("基础分页response")
public class BasePageResVO<T> implements Serializable {

    public BasePageResVO(int pageNo, int pageSize, long totalCount, List<T> data) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = (int)totalCount;
        this.totalPage = totalPage();
        this.data = data;
    }

    private Integer totalPage() {
        if (totalCount == 0 || pageSize == 0) {
            return 1;
        }
        return (int) Math.ceil((float) totalCount / pageSize);
    }

    @ApiModelProperty("当前页,索引从1开始")
    private Integer pageNo;

    @ApiModelProperty("页大小")
    private Integer pageSize;

    @ApiModelProperty("总页数")
    private Integer totalPage;

    @ApiModelProperty("总条数")
    private Integer totalCount;

    @ApiModelProperty("列表数据")
    private List<T> data;
}
